Facilitating value prediction to support speculative program execution

ABSTRACT

One embodiment of the present invention provides a system that predicts a result produced by a section of code in order to support speculative program execution. The system begins by executing the section of code using a head thread in order to produce a result. Before the head thread produces the result, the system generates a predicted result to be used in place of the result. Next, the system allows a speculative thread to use the predicted result in speculatively executing subsequent code that follows the section of code. After the head thread finishes executing the section of code, the system determines if a difference between the predicted result and the result generated by the head thread has affected execution of the speculative thread. If so, the system executes the subsequent code again using the result generated by the head thread. If not, the system performs a join operation to merge state associated with the speculative thread with state associated with the head thread. In one embodiment of the present invention, executing the subsequent code again involves performing a rollback operation for the speculative thread to undo actions performed by the speculative thread.

RELATED APPLICATION

[0001] This application hereby claims priority under 35 U.S.C. § 119 toU.S. Provisional Patent Application No. 60/208,429 filed May 31, 2000.

BACKGROUND

[0002] 1. Field of the Invention

[0003] The present invention relates to compilers and techniques forimproving computer system performance. More specifically, the presentinvention relates to a method and apparatus that facilitatesmethod-level and/or loop-level value prediction in order to supportspeculative execution during space and time dimensional execution of acomputer program.

[0004] 2. Related Art

[0005] As increasing semiconductor integration densities allow moretransistors to be integrated onto a microprocessor chip, computerdesigners are investigating different methods of using these transistorsto increase computer system performance. Some recent computerarchitectures exploit “instruction level parallelism,” in which a singlecentral processing unit (CPU) issues multiple instructions in a singlecycle. Given proper compiler support, instruction level parallelism hasproven effective at increasing computational performance across a widerange of computational tasks. However, inter-instruction dependenciesgenerally limit the performance gains realized from using instructionlevel parallelism to a factor of two or three.

[0006] Another method for increasing computational speed is “speculativeexecution” in which a processor executes multiple branch pathssimultaneously, or predicts a branch, so that the processor can continueexecuting without waiting for the result of the branch operation. Byreducing dependencies on branch conditions, speculative execution canincrease the total number of instructions issued.

[0007] Unfortunately, conventional speculative execution typicallyprovides a limited performance improvement because only a small numberof instructions can be speculatively executed. One reason for thislimitation is that conventional speculative execution is typicallyperformed at the basic block level, and basic blocks tend to includeonly a small number of instructions. Another reason is that conventionalhardware structures used to perform speculative execution can onlyaccommodate a small number of speculative instructions.

[0008] What is needed is a method and apparatus that facilitatesspeculative execution of program instructions at a higher level ofgranularity so that many more instructions can be speculativelyexecuted.

[0009] One problem with speculative execution is that data dependenciescan often limit the amount of speculative execution that is possible.For example, if a method returns a value that is used in subsequentcomputational operations, the value must be returned before thesubsequent computational operations can proceed. Hence, the systemcannot speculatively execute the subsequent computational operationsuntil the method returns.

[0010] However, return values for methods and other collections ofinstructions are often predictable. For example, a method veryfrequently returns the same value or a predictable value duringsuccessive invocations of the method. Furthermore, even if a methodreturn value is not predicted correctly, the method return value may notbe used by subsequent program instructions. Hence, it may be possible toimprove computer system performance by predicting a value produced by asection of program code in order to allow speculative execution toproceed.

[0011] Hence, what is needed is a method and an apparatus thatfacilitates predicting values generated by a section of program code inorder to facilitate speculative program execution.

[0012] Note that people have suggested performing value prediction for asingle computer instruction with long or unpredictable latency, such asa load operation or a square root operation. However, a predicted valuegenerated for a single instruction cannot be used to facilitateperforming speculative execution of program instructions at a higherlevel of granularity, for example predicting the outcome of a function.

SUMMARY

[0013] One embodiment of the present invention provides a system thatpredicts a result produced by a section of code in order to supportspeculative program execution. The system begins by executing thesection of code using a head thread in order to produce a result. Beforethe head thread produces the result, the system generates a predictedresult to be used in place of the result. Next, the system allows aspeculative thread to use the predicted result in speculativelyexecuting subsequent code that follows the section of code. After thehead thread finishes executing the section of code, the systemdetermines if a difference between the predicted result and the resultgenerated by the head thread has affected execution of the speculativethread. If so, the system executes the subsequent code again using theresult generated by the head thread. If not, the system performs a joinoperation to merge state associated with the speculative thread withstate associated with the head thread.

[0014] In one embodiment of the present invention, executing thesubsequent code again involves performing a rollback operation for thespeculative thread to undo actions performed by the speculative thread.

[0015] In one embodiment of the present invention, determining if thedifference affected execution of the speculative thread involvesdetermining if the speculative thread accessed the predicted result.

[0016] In one embodiment of the present invention, determining if thedifference affected execution of the speculative thread involvesdetermining if the predicted result differs from the result generated bythe head thread.

[0017] In one embodiment of the present invention, generating thepredicted result involves looking up a value based upon a programcounter for the program. In a variation on this embodiment, generatingthe predicted result involves additionally looking up the value basedupon at least one previously generated value for the result. In avariation on this embodiment, generating the predicted result involvesperforming a function on the value.

[0018] In one embodiment of the present invention, executing the sectionof code involves performing a method invocation, a function call or aprocedure call to execute the section of code.

[0019] In one embodiment of the present invention, the section of codeis a body of a loop in the program, and the result is a loop carrieddependency.

[0020] In one embodiment of the present invention, during a writeoperation to a memory element by the head thread, the system performsthe write operation to a primary version of the memory element andchecks status information associated with the memory element todetermine if the memory element has been read by the speculative thread.If the memory element has been read by the speculative thread, thesystem causes the speculative thread to roll back so that thespeculative thread can read a result of the write operation. If thememory element has not been read by the speculative thread, the systemperforms the write operation to a space-time dimensioned version of thememory element if the space-time dimensioned version exists. In avariation on this embodiment, performing the join operation involvesmerging the space-time dimensioned version of the memory element intothe primary version of the memory element and discarding the space-timedimensioned version of the memory element.

BRIEF DESCRIPTION OF THE FIGURES

[0021]FIG. 1 illustrates a computer system including two centralprocessing units sharing a common data cache in accordance with anembodiment of the present invention.

[0022]FIG. 2A illustrates sequential execution of methods by a singlethread.

[0023]FIG. 2B illustrates space and time dimensional execution of amethod in accordance with an embodiment of the present invention.

[0024]FIG. 3 illustrates the state of the system stack during space andtime dimensional execution of a method in accordance with an embodimentof the present invention.

[0025]FIG. 4 illustrates how memory is partitioned between stack andheap in accordance with an embodiment of the present invention.

[0026]FIG. 5 illustrates the structure of a primary version and aspace-time dimensioned version of an object in accordance with anembodiment of the present invention.

[0027]FIG. 6 illustrates the structure of a status word for an object inaccordance with an embodiment of the present invention.

[0028]FIG. 7 is a flow chart illustrating operations involved inperforming a write to a memory element by a head thread in accordancewith an embodiment of the present invention.

[0029]FIG. 8 is a flow chart illustrating operations involved inperforming a read to a memory element by a speculative thread inaccordance with an embodiment of the present invention.

[0030]FIG. 9 is a flow chart illustrating operations involved inperforming a write to a memory element by a speculative thread inaccordance with an embodiment of the present invention.

[0031]FIG. 10 is a flow chart illustrating operations involved inperforming a join between a head thread and a speculative thread inaccordance with an embodiment of the present invention.

[0032]FIG. 11 is a flow chart illustrating operations involved inperforming a join between a head thread and a speculative thread inaccordance with another embodiment of the present invention.

[0033]FIG. 12A illustrates an exemplary section of program code inaccordance with an embodiment of the present invention.

[0034]FIG. 12B illustrates how a speculative thread uses a predictedresult of a method to facilitate execution of a speculative thread inaccordance with an embodiment of the present invention.

[0035]FIG. 13 illustrates how the predicted result can be obtained froma lookup table in accordance with an embodiment of the presentinvention.

[0036]FIG. 14 is a flow chart illustrating the process of using apredicted result to facilitate speculative execution of a program inaccordance with an embodiment of the present invention.

DETAILED DESCRIPTION

[0037] The following description is presented to enable any personskilled in the art to make and use the invention, and is provided in thecontext of a particular application and its requirements. Variousmodifications to the disclosed embodiments will be readily apparent tothose skilled in the art, and the general principles defined herein maybe applied to other embodiments and applications without departing fromthe spirit and scope of the present invention. Thus, the presentinvention is not intended to be limited to the embodiments shown, but isto be accorded the widest scope consistent with the principles andfeatures disclosed herein.

[0038] The data structures and code described in this detaileddescription are typically stored on a computer readable storage medium,which may be any device or medium that can store code and/or data foruse by a computer system. This includes, but is not limited to, magneticand optical storage devices such as disk drives, magnetic tape, CDs(compact discs) and DVDs (digital video discs), and computer instructionsignals embodied in a carrier wave. For example, the carrier wave maycarry information across a communications network, such as the Internet.

[0039] Computer System

[0040]FIG. 1 illustrates a computer system including two centralprocessing units (CPUs) 102 and 104 sharing a common data cache 106 inaccordance with an embodiment of the present invention. In thisembodiment, CPUs 102 and 104 and data cache 106 reside on silicon die100. Note that CPUs 102 and 104 may generally be any type ofcomputational devices that allow multiple threads to executeconcurrently. In the embodiment illustrated in FIG. 1, CPUs 102 and 104are very long instruction word (VLIW) CPUs, which support concurrentexecution of multiple instructions executing on multiple functionalunits. VLIW CPUs 102 and 104 include instruction caches 112 and 120,respectively, containing instructions to be executed by VLIW CPUs 102and 104.

[0041] VLIW CPUs 102 and 104 additionally include load buffers 114 and122 as well as store buffers 116 and 124 for buffering communicationswith data cache 106. More specifically, VLIW CPU 102 includes loadbuffer 114 for buffering loads received from data cache 106, and storebuffer 116 for buffering stores to data cache 106. Similarly, VLIW CPU104 includes load buffer 122 for buffering loads received from datacache 106, and store buffer 124 for buffering stores to data cache 106.

[0042] VLIW CPUs 102 and 104 are additionally coupled together by directcommunication link 128, which facilitates rapid communication betweenVLIW CPUs 102 and 104. Note that direct communication link 128 allowsVLIW CPU 102 to write into communication buffer 126 within VLIW CPU 104.It also allows VLIW CPU 104 to write into communication buffer 118within VLIW CPU 102.

[0043] In the embodiment illustrated in FIG. 1, Data cache 106 is fullydual-ported allowing concurrent read and/or write accesses from VLIWCPUs 102 and 104. This dual porting eliminates cache coherence delaysassociated with conventional shared memory architectures that rely oncoherent caches.

[0044] In one embodiment of the present invention, data cache 106 is a16 K byte 4-way set-associative data cache with 32 byte cache lines.

[0045] Data cache 106, instruction caches 112 and instruction cache 120are coupled through switch 110 to memory controller 111. Memorycontroller 111 is coupled to dynamic random access memory (DRAM) 108,which is located off chip. Switch 110 may include any type of circuitryfor switching signal lines. In one embodiment of the present invention,switch 110 is a cross bar switch.

[0046] The present invention generally applies to any computer systemthat supports concurrent execution by multiple threads and is notlimited to the illustrated computing system. However, note that datacache 106 supports fast accesses to shared data items. These fastaccesses facilitate efficient sharing of status information between VLIWCPUs 102 and 104 to keep track of accesses to versions of memoryobjects.

[0047] Space-Time Dimensional Execution of Methods

[0048]FIG. 2A illustrates sequential execution of methods in aconventional computer system by a single head thread 202. In executing aprogram, head thread 202 executes a number of methods in sequence,including method A 204, method B 206 and method C 208.

[0049] In contrast, FIG. 2B illustrates space and time dimensionalexecution of a method in accordance with an embodiment of the presentinvention. In FIG. 2B, head thread 202 first executes method A 204 andthen executes method B 206. (For this example, assume that method B 206returns a void or some other value that is not used by method C 208.Alternatively, if method C 208 uses a value returned by method B206,assume that method C 208 uses a predicted return value from method B206.)

[0050] As head thread 202 executes method B 206, speculative thread 203executes method C 208 in a separate space-time dimension of the heap. Ifhead thread 202 successfully executes method B 206, speculative thread203 is joined with head thread 202. This join operation involves causingstate associated with the speculative thread 203 to be merged with stateassociated with the head thread 202 and the collapsing of the space-timedimensions of the heap.

[0051] If speculative thread 203 for some reason encounters problems inexecuting method C 208, speculative thread 203 performs a rollbackoperation. This rollback operation allows speculative thread 203 toreattempt to execute method C 208. Alternatively, head thread 202 canexecute method C 208 non-speculatively and speculative thread 203 canexecute a subsequent method.

[0052] There are a number of reasons why speculative thread 203 mayencounter problems in executing method C 208. One problem occurs whenhead thread 202 executing method B 206 writes a value to a memoryelement (object) after speculative thread 203 has read the same memoryelement. The same memory element can be read when the two space-timedimensions of the heap are collapsed at this memory element at the timeof the read by speculative thread 203. In this case, speculative thread203 should have read the value written by head thread 202, but insteadhas read a previous value. In this case, the system causes speculativethread 203 to roll back so that speculative thread 203 can read thevalue written by head thread 202.

[0053] Note that the term “memory element” generally refers to any unitof memory that can be accessed by a computer program. For example, theterm “memory element” may refer to a bit, a byte or a word memory, aswell as a data structure or an object defined within an object-orientedprogramming system.

[0054]FIG. 3 illustrates the state of the system stack during space andtime dimensional execution of a method in accordance with an embodimentof the present invention. Note that since programming languages such asthe Java programming language do not allow a method to modify the stackframe of another method, the system stack will generally be the samebefore method B 206 is executed as it is before method C 208 isexecuted. (This is not quite true if method B 206 returns a parameterthrough the system stack. However, return parameters are can beexplicitly dealt with as is described below.) Referring the FIG. 3,stack 300 contains method A frame 302 while method A 204 is executing.When method A 204 returns, method B 206 commences and method A frame 302is replaced by method B frame 304. Finally, when method B 206 returns,method C 208 commences and method B frame 304 is replaced by method Cframe 306. Note that since stack 300 is the same immediately beforemethod B 206 executed as it is immediately before method C 208 isexecuted, it is possible to execute method C 208 using a copy of stack300 without first executing method B 206.

[0055] In order to undo the results of speculatively executedoperations, updates to memory need to be versioned. The overheadinvolved in versioning all updates to memory can be prohibitivelyexpensive due to increased memory requirements, decreased cacheperformance and additional hardware required to perform the versioning.

[0056] Fortunately, not all updates to memory need to be versioned. Forexample, updates to local variables—such as a loop counter—on a systemstack are typically only relevant to the thread that is updating thelocal variables. Hence, even for speculative threads versioning updatesto these local variables is not necessary.

[0057] When executing programs written in conventional programminglanguages, such as C, it is typically not possible to determine whichupdates are related to the heap, and which updates are related to thesystem stack. These programs are typically compiled from a high-levellanguage representation into executable code for a specific machinearchitecture. This compilation process typically removes distinctionsbetween updates to heap and system stack.

[0058] The same is not true for new platform-independent computerlanguages, such as the JAVA™ programming language distributed by SUNMicrosystems, Inc. of Palo Alto, Calif. (Sun, the Sun logo, SunMicrosystems, and Java are trademarks or registered trademarks of SunMicrosystems, Inc. in the United States and other countries.) A programwritten in the Java programming language is typically compiled into aclass file containing Java byte codes. This class file can betransmitted over a computer network to a distant computer system to beexecuted on the distant computer system. Java byte codes are said to be“platform-independent,” because they can be executed across a wide rangeof computing platforms, so long as the computing platforms provide aJava virtual machine.

[0059] A Java byte code can be executed on a specific computing platformby using an interpreter or a just in time (JIT) compiler to translatethe Java byte code into machine code for the specific computingplatform. Alternatively, a Java byte code can be executed directly on aJava byte code engine running on the specific computing platform.

[0060] Fortunately, a Java byte code contains more syntactic informationthan conventional machine code. In particular, the Java byte codesdifferentiate between accesses to local variables in the system stackand accesses to the system heap. Furthermore, programs written in theJava programming language do not allow conversion between primitive andreference types. Such conversion can make it hard to differentiateaccesses to the system stack from accesses to the system heap at compiletime.

[0061] Data Structures to Support Space-Time Dimensional Execution

[0062]FIG. 4 illustrates how memory is partitioned between stack andheap in accordance with an embodiment of the present invention. In FIG.4, memory 400 is divided into a number of regions including heap 402,stacks for threads 404 and speculative heap 406. Heap 402 comprises aregion of memory from which objects are allocated. Heap 402 is furtherdivided into younger generation region 408 and older generation region410 for garbage collection purposes. For performance reasons, garbagecollectors typically treat younger generation objects differently fromolder generation objects. Stack for threads 404 comprises a region ofmemory from which stacks for various threads are allocated. Speculativeheap 406 contains the space-time dimensioned values of all memoryelements where the two space-time dimensions of the heap are notcollapsed. This includes space-time dimensional versions of objects, forexample, version 510 of object 500 as shown in FIG. 5, and objectscreated by speculative thread 203. For garbage collection purposes,these objects created by speculative thread 203 can be treated asbelonging to a generation that is younger than objects within youngergeneration region 408.

[0063]FIG. 5 illustrates the structure of a primary version of object500 and a space-time dimensioned version of object 510 in accordancewith an embodiment of the present invention.

[0064] Primary version of object 500 is referenced by object referencepointer 501. Like any object defined within an object-orientedprogramming system, primary version of object 500 includes data region508, which includes one or more fields containing data associated withprimary version of object 500. Primary version of object 500 alsoincludes method vector table pointer 506. Method vector table pointer506 points to a table containing vectors that point to the methods thatcan be invoked on primary version of object 500.

[0065] Primary version of object 500 also includes space-timedimensioned version pointer 502, which points to space-time dimensionedversion of object 510, if the two space-time dimensions are notcollapsed at this object. Note that in the illustrated embodiment of thepresent invention, space-time dimensioned version 510 is alwaysreferenced indirectly through space-time dimensioned version pointer502. Primary version of object 500 additionally includes status word504, which contains status information specifying which fields from dataregion 508 have been written to or read by speculative thread 203.Space-time dimensioned version of object 510 includes only data region518.

[0066]FIG. 6 illustrates the structure of status word 504 in accordancewith an embodiment of the present invention. In this embodiment, statusword 504 includes checkpoint number 602 and speculative bits 603.Speculative bits 603 includes read bits 604 and write bits 606. Whenstatus word 504 needs to be updated due to a read or a write byspeculative thread 203, checkpoint number 602 is updated with thecurrent time of the system. The current time in the time dimension ofthe system is advanced discretely at ajoin or a rollback. This allowscheckpoint number 602 to be used as a qualifier for speculative bits603. If checkpoint number 602 is less than the current time, speculativebits 603 can be interpreted as reset.

[0067] Read bits 604 keep track of which fields within data region 508have been read since the last join or rollback. Correspondingly, writebits 606 keep track of which fields within data region 508 have beenwritten since the last join or rollback. In one embodiment of thepresent invention, read bits 604 includes one bit for each field withindata region 508. In another embodiment, read bits includes fewer bitsthan the number of fields within data region 508. In this embodiment,each bit within read bits 604 corresponds to more than one field in dataregion 508. For example, if there are eight read bits, each bitcorresponds to every eighth field. Write bits 606 similarly cancorrespond to one or multiple fields within data region 508.

[0068] Space-Time Dimensional Update Process

[0069] Space-time dimensioning occurs during selected memory updates.For local variable and operand accesses to the system stack, nospace-time dimensioned versions exist and nothing special happens.During read operations by head thread 202 to objects in the heap 402,again nothing special happens.

[0070] Special operations are involved in write operations by headthread 202 as well as read and write operations by speculative thread203. These special operations are described in more detail withreference to FIGS. 7, 8 and 9 below.

[0071]FIG. 7 is a flow chart illustrating operations involved in a writeoperation to an object by a head thread 202 in accordance with anembodiment of the present invention. The system writes to the primaryversion of object 500 and the space-time dimensioned version of object510 if the two space-time dimensions are not collapsed at this point(step 702). Next, the system checks status word 504 within primaryversion of object 500 to determine whether a rollback is required (step704). A rollback is required if speculative thread 203 previously readthe data element. The same memory element can be read when the twospace-time dimensions of the heap are collapsed at this memory elementat the time of the read by speculative thread 203. A rollback is alsorequired if speculative thread 203 previously wrote to the object andthus ensured that the two dimensions of the object are not collapsed atthis element, and if the current write operation updates both primaryversion of object 500 and space-time dimensioned version of object 510.

[0072] If a rollback is required, the system causes speculative thread203 to perform a rollback operation (step 706). This rollback operationallows speculative thread 203 to read from (or write to) the objectafter head thread 202 writes to the object.

[0073] Note that in the embodiment of the present invention illustratedin FIG. 7 the system performs writes to both primary version 500 andspace-time dimensioned version 510. In an alternative embodiment, thesystem first checks to determine if speculative thread 203 previouslywrote to space-time dimensioned version 510. If not, the system writesto both primary version 500 and space-time dimensioned version 510. Ifso, the system only writes to primary version 500.

[0074]FIG. 8 is a flow chart illustrating operations involved in a readoperation to an object by speculative thread 203 in accordance with anembodiment of the present invention. During this read operation, thesystem sets a status bit in status word 504 within primary version ofobject 500 to indicate that primary version 500 has been read (step802). Speculative thread 203 then reads space-time dimensioned version510, if it exists. Otherwise, speculative thread 203 reads primaryversion 500.

[0075]FIG. 9 is a flow chart illustrating operations involved in a writeoperation to a memory element by speculative thread 203 in accordancewith an embodiment of the present invention. If a space-time dimensionedversion 510 does not exist, the system creates a space-time dimensionedversion 510 in speculative heap 406 (step 902). The system also updatesstatus word 504 to indicate that speculative thread 203 has written tothe object if such updating is necessary (step 903). The system nextwrites to space-time dimensioned version 510 (step 904). Such updatingis necessary if head thread 202 must subsequently choose between writingto both primary version 500 and space-time dimensioned version 510, orwriting only to primary version 500 as is described above with referenceto FIG. 7.

[0076]FIG. 10 is a flow chart illustrating operations involved in a joinoperation between head thread 202 and a speculative thread 203 inaccordance with an embodiment of the present invention. A join operationoccurs for example when head thread 202 reaches a point in the programwhere speculative thread 203 began executing. The join operation causesstate associated with the speculative thread 203 to be merged with stateassociated with the head thread 202. This involves copying and/ormerging the stack of speculative thread 203 into the stack of headthread 202 (step 1002). It also involves merging space-time dimensionand primary versions of objects (step 1004) as well as possibly garbagecollecting speculative heap 406 (step 1006). In one embodiment of thepresent invention, one of threads 202 or 203 performs steps 1002 and1006, while the other thread performs step 1004.

[0077]FIG. 11 is a flow chart illustrating operations involved in ajoinoperation between head thread 202 and a speculative thread 203 inaccordance with another embodiment of the present invention. In thisembodiment, speculative thread 203 carries on as a pseudo-head thread.As a pseudo-head thread, speculative thread 203 uses indirection toreference space-time dimensioned versions of objects, but does not markobjects or create versions. While speculative thread 203 is acting as apseudo-head thread, head thread 202 updates primary versions of objects.

[0078] Value Prediction to Support Speculative Execution

[0079]FIG. 12A illustrates an exemplary section of program code inaccordance with an embodiment of the present invention. This exemplarysection of program code includes a method A, which contains code thatinvokes a method B( ) in order to return a result. This result is usedin executing subsequent code within method A.

[0080]FIG. 12B illustrates how speculative thread 203 uses a predictedresult 1312 of method B( ) to facilitate execution of speculative thread203 in accordance with an embodiment of the present invention. Asillustrated in FIG. 12B, head thread 202 begins executing method A. Atsome point during this execution, head thread 202 begins executingmethod B( ) in order to generate a result. At this point, speculativethread 203 predicts the result of the method B( ) and continuesexecuting method A( ) at a point in the program after the return frommethod B. Note that head thread 202 is still executing method B.

[0081] When head thread 202 eventually finishes executing method B, itattempts to perform a join operation with speculative thread 203. Atthis point, the system determines whether or not a mispredicted resultof method B( ) affected the execution of speculative thread 203. If so,the system causes speculative thread 203 to perform a rollbackoperation. Otherwise, the system allows speculative thread 203 to joinwith head thread 202. The above-described process for using a predictedresult 1312 to facilitate speculative execution is described in moredetail below with reference to FIG. 14.

[0082] Note that although the present invention is described in thecontext of predicted a value returned by a method. The present inventioncan generally be used in predicting a value produced by any section ofcode. For example, in another embodiment of the present invention, thesystem predicts a loop carried dependency generated within the body of aprogram loop. Note that a loop carried dependency can include a variablethat is updated within every iteration of a program loop.

[0083]FIG. 13 illustrates how the predicted result 1312 can be obtainedfrom a lookup table 1310 in accordance with an embodiment of the presentinvention. In this embodiment, the system uses a lookup table 1310 tolookup predicted result 1312. Lookup table 1310 is indexed with aprogram counter 1304 (and is optionally indexed with a last resultproduced 1306) to retrieve predicted result 1312.

[0084] In one embodiment of the present invention, program counter 1304contains the address from which method B( ) was invoked. In anotherembodiment, program counter 1304 contains the address at which the codethat implements method B( ) is located. Note that lookup table 1310 maysimply contain the last value returned by method B. However, ingeneral, any predicted result can be stored within lookup table 1310.

[0085]FIG. 14 is a flow chart illustrating the process of using apredicted result 1312 of a method to facilitate speculative execution ofa program in accordance with an embodiment of the present invention. Thesystem begins by executing a section of code (such as method B( ) fromFIG. 12A) using head thread 202 (step 1402). Next, the system predictsthe result returned by method B( ) (step 1404).

[0086] As mentioned above, any method for predicting the result ofreturned by a method can be used with the present invention. Forexample, the predicted result 1312 can be the last value returned by themethod or that last value returned by the method when invoked from thesame address. Alternatively, the predicted result 1312 can be a functionof the last value returned by the method, such as the last value plus aconstant. The predicted result 1312 can also be fixed default value.

[0087] Next, the predicted result is used to execute subsequent codefollowing the invocation of method B( ) using speculative thread 203(step 1406). At this point, head thread 202 has not finished executingmethod B.

[0088] After head thread 202 finishes executing method B, the systemdetermines whether a read bit associated with predicted result 1312 hasbeen set (step 1408). If not, speculative thread 203 has not readpredicted result 1312. Hence, predicted result 1312 cannot have affectedthe execution of speculative thread 203. Hence, the system allows ajoinoperation to proceed between head thread 202 and speculative thread 203(step 1414).

[0089] Note that every time speculative thread 203 reads a return valuefor a method, speculative thread 203 marks a corresponding read bit toindicate that the return value has been read. This marking occurs inspite of the fact that the return value is located within a stack, andis not located within a heap.

[0090] If the read bit has been set, the system determines whether theresult returned by method B( ) matches the predicted result (step 1412).If so, the system also allows a join operation to proceed between headthread 202 and speculative thread 203 (step 1414).

[0091] If the result returned by method B( ) does not match thepredicted result 1312, the result was mispredicted. Furthermore, recallthat speculative thread 203 has read the mispredicted result. Hence, itis very likely that speculative thread 203 has generated erroneousresults. In this case, the system causes speculative thread 203 to rollback to undo any results generated by speculative thread 203 (step1416). The system may additionally adjust the prediction mechanism basedupon the result returned by head thread 292 (step 1418). Finally, thesystem again executes the subsequent code following method B( ) basedupon the result returned by method B( ) instead of the erroneouspredicted result 1312 (step 1420).

[0092] The foregoing descriptions of embodiments of the invention havebeen presented for purposes of illustration and description only. Theyare not intended to be exhaustive or to limit the invention to the formsdisclosed. Accordingly, many modifications and variations will beapparent to practitioners skilled in the art. Additionally, the abovedisclosure is not intended to limit the invention. The scope of theinvention is defined by the appended claims.

What is claimed is:
 1. A method that predicts a result produced by asection of code in order to support speculative program execution, thesection of code including a plurality of program instructions, themethod comprising: executing the section of code within a program usinga head thread, wherein executing the section of code produces theresult; before the head thread produces the result, generating apredicted result to be used in place of the result; allowing thespeculative thread to speculatively execute subsequent code within theprogram using the predicted result, wherein the subsequent code followsthe section of code in an execution stream of the program; and after thehead thread finishes executing the section of code, determining if adifference between the predicted result and the result generated by thehead thread affected execution of the speculative thread; if thedifference affected execution of the speculative thread, executing thesubsequent code again using the result generated by the head thread; andif the difference did not affect execution of the speculative thread,performing a join operation to merge state associated with thespeculative thread with state associated with the head thread.
 2. Themethod of claim 1, wherein executing the subsequent code again involvesperforming a rollback operation for the speculative thread to undoactions performed by the speculative thread.
 3. The method of claim 1,wherein determining if the difference affected execution of thespeculative thread involves determining if the speculative threadaccessed the predicted result.
 4. The method of claim 1, whereindetermining if the difference affected execution of the speculativethread involves determining if the predicted result differs from theresult generated by the head thread.
 5. The method of claim 1, whereingenerating the predicted result involves looking up a value based upon aprogram counter for the program.
 6. The method of claim 5, whereingenerating the predicted result involves additionally looking up thevalue based upon at least one previously generated value for the result.7. The method of claim 5, wherein generating the predicted resultinvolves performing a function on the value.
 8. The method of claim 1,wherein executing the section of code involves performing one of: amethod invocation to execute the section of code; a function call toexecute the section of code; and a procedure call to execute the sectionof code.
 9. The method of claim 1, wherein the section of code is a bodyof a loop in the program, and the result is a loop carried dependencyfor the loop.
 10. The method of claim 1, wherein during a writeoperation to a memory element by the head thread, the method furthercomprises: performing the write operation to a primary version of thememory element; checking status information associated with the memoryelement to determine if the memory element has been read by thespeculative thread; if the memory element has been read by thespeculative thread, causing the speculative thread to roll back so thatthe speculative thread can read a result of the write operation; and ifthe memory element has not been read by the speculative thread,performing the write operation to a space-time dimensioned version ofthe memory element if the space-time dimensioned version exists.
 11. Themethod of claim 10, wherein performing the join operation involvesmerging the space-time dimensioned version of the memory element intothe primary version of the memory element and discarding the space-timedimensioned version of the memory element.
 12. An apparatus thatfacilitates predicting a result produced by a section of code in orderto support speculative program execution, the section of code includinga plurality of program instructions, the apparatus comprising: a headthread that is configured to execute the section of code within aprogram, wherein executing the section of code produces the result; aprediction mechanism that is configured to generate a predicted resultto be used in place of the result before the head thread produces theresult; a speculative thread that is configured to speculatively executesubsequent code within the program using the predicted result, whereinthe subsequent code follows the section of code in an execution streamof the program; and a determination mechanism that is configured todetermine if a difference between the predicted result and the resultgenerated by the head thread affected execution of the speculativethread; and a joining mechanism that is configured to merge stateassociated with the speculative thread with state associated with thehead thread if the difference did not affect execution of thespeculative thread; wherein if the difference affected execution of thespeculative thread, the apparatus is configured to execute thesubsequent code again using the result generated by the head thread. 13.The apparatus of claim 12, wherein while executing the subsequent codeagain, the apparatus is configured to perform a rollback operation forthe speculative thread to undo actions performed by the speculativethread.
 14. The apparatus of claim 12, wherein the determinationmechanism is configured to determine if the speculative thread accessedthe predicted result.
 15. The apparatus of claim 12, wherein thedetermination mechanism is configured to determine if the predictedresult differs from the result generated by the head thread.
 16. Theapparatus of claim 12, wherein the prediction mechanism is configured togenerate the predicted result by looking up a value based upon a programcounter for the program.
 17. The apparatus of claim 16, wherein theprediction mechanism is configured to generate the predicted result byadditionally looking up the value based upon at least one previouslygenerated value for the result.
 18. The apparatus of claim 16, whereinthe prediction mechanism is configured to generate the predicted resultby performing a function on the value.
 19. The apparatus of claim 12,wherein the section of code includes one of, a method, a function and aprocedure.
 20. The apparatus of claim 12, wherein the section of code isa body of a loop in the program, and the result is a loop carrieddependency for the loop.
 21. The apparatus of claim 12, furthercomprising a mechanism that performs write operations for the headthread, the mechanism being configured to: perform a write operation toa primary version of a memory element; check status informationassociated with the memory element to determine if the memory elementhas been read by the speculative thread; cause the speculative thread toroll back so that the speculative thread can read a result of the writeoperation if the memory element has been read by the speculative thread;and perform the write operation to a space-time dimensioned version ofthe memory element if the space-time dimensioned version exists and ifthe memory element has not been read by the speculative thread.
 22. Theapparatus of claim 21, wherein the joining mechanism is configured to:merge the space-time dimensioned version of the memory element into theprimary version of the memory element; and to discard the space-timedimensioned version of the memory element.
 23. A computer-readablestorage medium storing instructions that when executed by a computercause the computer to perform a method that predicts a result producedby a section of code in order to support speculative program execution,the section of code including a plurality of program instructions, themethod comprising: executing the section of code within a program usinga head thread, wherein executing the section of code produces theresult; before the head thread produces the result, generating apredicted result to be used in place of the result; allowing thespeculative thread to speculatively execute subsequent code within theprogram using the predicted result, wherein the subsequent code followsthe section of code in an execution stream of the program; and after thehead thread finishes executing the section of code, determining if adifference between the predicted result and the result generated by thehead thread affected execution of the speculative thread; if thedifference affected execution of the speculative thread, executing thesubsequent code again using the result generated by the head thread; andif the difference did not affect execution of the speculative thread,performing a join operation to merge state associated with thespeculative thread with state associated with the head thread.
 24. Thecomputer-readable storage medium of claim 23, wherein executing thesubsequent code again involves performing a rollback operation for thespeculative thread to undo actions performed by the speculative thread.